// pages/myPages/setPage/changePassWordPage/setNewPassWordPage/setNewPassWordPage.js
var path = "../../../../../../image/"
/*var bip39 = require('../../../../../../utils/bitcoinTool/bip39.js')
var tool = require('../../../../../../utils/bitcoinTool/tool.js')
var hdkey = tool.hdkey;
var CryptoJs = require('../../../../../../utils/bitcoinTool/CryptoJs.min.js');
var buffer = require('../../../../../../utils/bitcoinTool/bufferHD.js');
var Buffer = buffer.buffer.Buffer
var HDkey = buffer.HDkey*/
var wallet = require('../../../../../wallet.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    setPassword: '',
    SetP: '',
    IPW: true, //是否密文显示 true为密文， false为明文。 
    path: path,
    urlImage: 'icon_buxianshixinxi.png',
    newLoginPwd: {},
    NPSW:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      NPSW: options.NPSW
    })
    
  },
  setPassword: function (e) {
    this.setData({
      SetP: e.detail.value
    })
  },
  getVerifyingCode: function (e) {
    var FpassWord = this.data.NPSW;
    var SpassWord = this.data.SetP;
    var miWord = wx.getStorageSync('pswd');
    var getWallet = wx.getStorageSync('walletKey');
    var hdWallet =  wallet.decode(miWord, getWallet);//解密
    if (FpassWord == SpassWord){
      var val = SpassWord;
      //var pswd = CryptoJs.MD5(val).toString();
      var pswd = wallet.MD5jiami(val)
      if (pswd) {
        var walletKey = JSON.stringify(hdWallet.toJSON())
        //console.log(walletKey)
        walletKey = wallet.encryption(pswd, walletKey);//钱包加密；
        wx.setStorageSync('pswd', pswd);
        wx.setStorageSync('walletKey', walletKey)
        //console.log(HDkey.fromJSON)
      }
      wx.navigateBack({
        delta: 4
      })
    }else{
      wx.showToast({
        title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].notConsistent : wx.T.locales['en'].notConsistent,
        icon: 'none',
        duration: 2000
      })
    }
    this.setData({
      SetP: ''
    })
  },
  clear: function () {
    this.setData({
      SetP: ''
    })
  },
  ciphertext: function () {
    if (this.data.urlImage == 'icon_buxianshixinxi.png') {
      this.setData({
        urlImage: 'icon_xianshixinxi.png',
        IPW: false
      })
    } else {
      this.setData({
        urlImage: 'icon_buxianshixinxi.png',
        IPW: true
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      newLoginPwd: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].changePwd : wx.T.locales['en'].changePwd
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})